package mysql

import (
	"rent-master/rent/rent"

	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(30);not null;comment:'名称'"`
	Password string `gorm:"type:varchar(32);not null;comment:'密码'"`
}
type Rent struct {
	gorm.Model
	Title string  `gorm:"type:varchar(30);not null;comment:'名称'"`
	Price float64 `gorm:"type:decimal(10,2);not null;comment:'价格'"`
	Area  string  `gorm:"type:varchar(100);not null;comment:'地址'"`
}

func (r *Rent) RentList(db *gorm.DB, lists []*rent.RentList) ([]*rent.RentList, error) {
	err2 := db.Model(r).
		Select("rents.id as rent_id",
			"title",
			"price",
			"area").Find(&lists).Error
	return lists, err2
}

func (r *Rent) RentShow(db *gorm.DB, id int64) error {
	return db.Debug().Where("id", id).Find(r).Error
}
